package us.luosl.hadoop.hive.udf;

import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;

/**
 * 计算字符串长度
 * CREATE TEMPORARY FUNCTION len AS 'us.luosl.hadoop.hive.udf.Len';
 * Created by luosl on 2018/9/4.
 */
public class Len extends UDF{

    public IntWritable evaluate(Text s) {
        IntWritable result = new IntWritable();
        if (s == null) {
            result.set(0);
        }else{
            result.set(s.toString().length());
        }
        return result;
    }

}
